﻿using System;
using SVTTranslateTextEngine.Core.Entries;

namespace SVTTranslateTextEngine.Core.Log
{
    /// <summary>
    /// This class is handle the log how to write
    /// </summary>
    public class LogWriter
    {
        /// <summary>
        /// the root dir for saving log files
        /// </summary>
        private readonly string m_BaseDirPath;

        protected FileAccessHelper m_FileAccessor = new FileAccessHelper();


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="szBaseDirPath">the root dir for saving log files</param>
        public LogWriter(string szBaseDirPath)
        {
            m_FileAccessor.CreateDir(szBaseDirPath);
            m_BaseDirPath = szBaseDirPath;
        }

        /// <summary>
        /// Save the LogInfo object to the CSV file.
        /// </summary>
        /// <param name="logInfo">input the LogInfo Object</param>
        public void SaveLogByCSV(LogInfo logInfo)
        {
            string logDirPath = m_BaseDirPath + "\\" + DateTime.Now.ToString(LogInfo.DATE_STRING) + "\\" + logInfo;
            m_FileAccessor.CreateDir(logDirPath);
            string logFilePath = logDirPath + "\\" + DateTime.Now.ToString(LogInfo.HOUR_KEY) + ".csv";
            m_FileAccessor.WriteTextContext(logInfo + "\r\n", logFilePath, true);
        }
    }
}